import moment from "moment";
import mDay from "../component/moment1.vue";
export default {
  components: {
    "single-Q": () => import("./cmms/single-Q"),
    "multiple-Q": () => import("./cmms/multiple-Q"),
    "stuff-Q": () => import("./cmms/stuff-Q"),
    "exam-rate": () => import("./cmms/exam-rate"),
    mDay
  },
  data() {
    return {
      // 包训一下选项数据
      wr_obj: null,
      //考试结束时间
      examEnd: {
        jTime: "2021-08-12 21:00:00",
        // jTime: "2021-08-13 15:54:00",
        fTime: "2021-08-13 22:00:00",
        gTime: "2021-08-14 22:00:00",
        sTime: "2021-08-15 23:00:00",
        // sTime: "2021-08-10 09:00:00",
        zTime: "2021-08-15 23:00:00"
      },
      gbTime: {
        //公布时间
        jTime: "2021-08-13 08:00:00",
        fTime: "2021-08-14 08:00:00",
        gTime: "2021-08-15 08:00:00",
        sTime: "2021-08-16 08:00:00",
        zTime: "2021-08-16 08:00:00"
      },
      // 训练id 保存
      bXlId: null,
      // 保存时候所需的试卷id
      colectId: "",
      scrollNum: 0,
      paper_exam_result: null, //评分
      paper_config: {
        paper_info: {},
        Q_count: null,
        single_Q_info: null,
        multiple_Q_info: null,
        stuff_info: null,
        single_Q_json: null,
        multiple_Q_json: null,
        stuff_Q_json: null
      },
      lazy_load: {
        total: 0,
        current_length: 0,
        page: 1,
        size: 20 //speed
      },
      count_down: {
        timer: null,
        use: false,
        total_time: 0,
        remaining_time: 0,
        pass_time: 0,
        is_pause: false
      },
      submit_data: null,
      //modal
      submit_tip_modal: {
        use: false,
        not_compile_Q_num: 0
      },
      request_id: "",
      redo: 0,
      lookDat: null,
      startRun: 0,
      timers: null,
      subNun: 0,
      subTimer: null,
      // 自动胶卷弹框
      autoSubmit: false,
      subBtn: true
    };
  },
  watch: {
    paper_config: {
      handler(newData) {
        // console.log(newData, "newData");
        // if(newData.multiple_Q_info.zs*1==newData.multiple_Q_json.length){
        //   this.paper_config.multiple_Q_json.forEach(element => {
        //     element.yx_da=element.yx_da[0].split("")
        //   });
        // }
      },
      deep: true
    },
    subNun: {
      handler(newData) {
        if (this.subNun == 1) {
          // this.autoSubmit = true;
          // this.subTimer = setTimeout(() => {
          //   this.on_submit();
          // }, 3000);
        }
      }
    },
    text_remaining_time: {
      handler() {
        if (this.text_remaining_time.s * 1 < 0) {
          this.on_submit();
        }
      },
      deep: true
    }
  },
  methods: {
    singleClick(data) {
      this.saveAnswers(data);
    },
    // 保存答题记录
    saveAnswers(data) {
      let obj = {
        token: this.$store.state.$user.token,
        shijuan_id: data.sj_id * 1,
        xl_id: this.bXlId * 1,
        xh: data.xh * 1,
        st_id: data.id * 1,
        tx: data.tx * 1,
        da: data.yx_da.join(""),
        dc: data.yx_da.join("") == data.da ? "对" : "错",
        df: data.yx_da.join("") == data.da ? 1 : 0,
        ys: this.startRun,
        tzt: data.tzt * 1
      };
      this.$api.paper.saveAnswers(obj).then(res => {
        this.startRun = 0;
      });
    },
    // 万人模考交卷（退出）
    tcbc() {
     
      console.log(obj)
      if (!sessionStorage.getItem("setQ")) return this.$Message.error({
          background: true,
          content: "未做题"
        });
        let obj = {
          token: this.$store.state.$user.token,
          xl_id: this.paper_config.paper_info.xl_id * 1,
          xh: JSON.parse(sessionStorage.getItem("setQ")).xh * 1,
          ys: this.startRun * 1
        };
      this.$api.paper.tcbc(obj).then(res => {
        if (res.data.event != "100")
          return this.$Message.error({
            background: true,
            content: "做题进度保存失败"
          });
        this.$Message.success({
          background: true,
          content: "已保存当前做题进度"
        });
      });
    },
    // 万人模考交卷
    jjzt() {
      this.subBtn = false;
      this.$Message.info({
        background: true,
        content: "交卷中请稍等"
      });
      let obj = {
        token: this.$store.state.$user.token,
        shijuan_id: this.$route.params.paper_id * 1,
        xl_id: this.paper_config.paper_info.xl_id * 1,
        xh: JSON.parse(sessionStorage.getItem("setQ")).xh * 1,
        ys: this.startRun * 1
      };
      this.$api.paper.jjzt(obj).then(res => {
        let resObj = {
          data: res.data.data,
          list: res.data.list
        };
        this.submit_tip_modal.use = false;
        this.paper_exam_result = resObj;
        sessionStorage.setItem("resObj", JSON.stringify(resObj));
        this.autoSubmit = false;
      });
    },
    changeTime() {
      this.startRun = 0;
    },
    settimer() {
      this.timers = setInterval(() => {
        this.startRun++;
      }, 1000);
    },
    // 监听时间变化
    submitPaper() {
      this.autoSubmit = true;
      // this.$nextTick(() => {
        this.subTimer = setTimeout(() => {
          this.on_submit();
        }, 3000);
      // });
    },

    pxscroll(e) {
      let top = e.srcElement.scrollingElement.scrollTop; // 获取页面滚动高度
      this.scrollNum = top;
    },
    clearexam() {
      // this.$router.go(0);
    },
    on_submit(n) {
      //提取数据
      const {
        paper_info,
        single_Q_json,
        multiple_Q_json
        // stuff_Q_json
      } = this.paper_config;

      //fix yx_da必须为数组
      const stuff_Q_json = JSON.parse(
        JSON.stringify(this.paper_config.stuff_Q_json)
      );
      stuff_Q_json.map(v => (v.yx_da = [v.yx_da]));

      //统计未完成
      let not_compile_Q_num = 0;
      const Q_list = [...single_Q_json, ...multiple_Q_json, ...stuff_Q_json];
      Q_list.map(
        v => (v.yx_da.length === 0 || v.yx_da[0] === "") && not_compile_Q_num++
      );
      this.submit_data = {
        lb_id: paper_info.lb_id,
        sj_id: paper_info.paper_id || paper_info.sj_id,
        xl_id: paper_info.xl_id,
        yy_sc: Math.ceil(this.count_down.pass_time / 1000),
        zts: Q_list.length,
        st_list: encodeURIComponent(JSON.stringify(Q_list))
      };
      let num = 0;
      num = n;
      if (not_compile_Q_num !== 0 && num == 1) {
        this.use_submit_tip_modal(not_compile_Q_num);
      } else {
        this.submit();
      }
    },
    submit() {
      clearTimeout(this.subTimer);
      // #start 60秒之内提交无效
      if (this.$route.params.st_lx == "5") return this.jjzt();
      // if (this.submit_data.yy_sc < 20) return this.$Modal.info({
      //   title: '本次操作无效',
      //   content: '做题时间太短,系统判定为无效<h6 class="c-error">计时已暂停,开始后可继续做题</h6>',
      //   onOk: () => {
      //     this.pause_count_down();
      //   },
      // });
      this.submit_tip_modal.use = false; //隐藏modal
      let obj = {
        token: this.$store.state.$user.token,
        lb_id: this.submit_data.lb_id,
        sj_id: this.submit_data.sj_id,
        xl_id: this.submit_data.xl_id,
        yy_sc: this.submit_data.yy_sc,
        zts: this.submit_data.zts,
        st_list: this.submit_data.st_list,
        request_id: this.$route.params.st_lx == 5 ? 1 : this.$route.params.st_lx
        // request_id: this.$route.params.st_lx
      };
      delete obj.user_id;
      this.$api.paper.submit(obj).then(rst => {
        if (rst.data.event === "100") {
          this.paper_exam_result = rst.data;
          clearInterval(this.count_down.timer);
        } else {
          this.$Modal.info({
            title: "提示",
            content: rst.data.msg
          });
        }
      });
    },

    // 万人模考

    // 智能练习 开始做题
    aiJl() {
      const lazy_load = this.lazy_load;
      let obj = JSON.parse(sessionStorage.getItem("znObj"));
      this.$api.paper.aiJl(obj).then(rst => {
        if (rst.data.event !== "100") return;
        this.colectId = rst.data.sj_id + "";
        const paper_config = this.paper_config,
          rst_data = rst.data;

        //保存试卷 , 试题基本信息
        paper_config.paper_info = rst_data;
        paper_config.single_Q_info = rst_data.d_info;
        paper_config.multiple_Q_info = rst_data.dx_info;
        paper_config.stuff_info = rst_data.cl_info;
        //Q  main
        const Q_data = rst_data.st_list;
        const single_Q_json = [],
          multiple_Q_json = [],
          stuff_Q_json = []; //区分单选 多选
        //保存懒加载状态
        lazy_load.total = rst_data.num;
        lazy_load.current_length = Q_data.length;
        Q_data.map(v => {
          switch (v.tx) {
            case "1":
              single_Q_json.push(v);
              break;
            case "2":
              multiple_Q_json.push(v);
              break;
            case "3":
              v.yx_da = "";
              v.nr = v.nr.replace(/\n+/g, "<br/>");
              stuff_Q_json.push(v);
              break;
          }
        });
        paper_config.single_Q_json = single_Q_json;
        paper_config.multiple_Q_json = multiple_Q_json;
        paper_config.stuff_Q_json = stuff_Q_json;
        console.log(
          paper_config,
          "paper_config----paper_config*****************"
        );
        //倒计时
        this.count_down.total_time = this.count_down.remaining_time =
          rst_data.sc * 60 * 1000;
        this.start_count_down();
      });
    },
    // 每日一练重新做题
    redoDaily() {
      const lazy_load = this.lazy_load;
      let everyDa = JSON.parse(sessionStorage.getItem("daylay"));
      let obj = {
        lb_id: this.$route.params.product_id,
        token: this.$store.state.$user.token,
        kmlb: everyDa.kmlb,
        sj_id: everyDa.sj_id || everyDa.id
      };
      this.$api.paper.redoDaily(obj).then(rst => {
        if (rst.data.event !== "100") return;
        this.colectId = rst.data.sj_id + "";
        const paper_config = this.paper_config,
          rst_data = rst.data;
        //保存试卷 , 试题基本信息
        paper_config.paper_info = rst_data;
        paper_config.single_Q_info = rst_data.d_info;
        paper_config.multiple_Q_info = rst_data.dx_info;
        paper_config.stuff_info = rst_data.cl_info;
        //Q  main
        const Q_data = rst_data.st_list;
        const single_Q_json = [],
          multiple_Q_json = [],
          stuff_Q_json = []; //区分单选 多选
        //保存懒加载状态
        lazy_load.total = rst_data.num;
        lazy_load.current_length = Q_data.length;
        Q_data.map(v => {
          switch (v.tx) {
            case "1":
              single_Q_json.push(v);
              break;
            case "2":
              multiple_Q_json.push(v);
              break;
            case "3":
              v.yx_da = "";
              v.nr = v.nr.replace(/\n+/g, "<br/>");
              stuff_Q_json.push(v);
              break;
          }
        });
        paper_config.single_Q_json = single_Q_json;
        paper_config.multiple_Q_json = multiple_Q_json;
        paper_config.stuff_Q_json = stuff_Q_json;
        //载剩余数据
        lazy_load.current_length < lazy_load.total && this.zjst_json();
        //倒计时
        this.count_down.total_time = this.count_down.remaining_time =
          rst_data.sc * 60 * 1000;
        this.start_count_down();
      });
    },
    // 每日一练
    startDaily() {
      const lazy_load = this.lazy_load;
      let everyDa = JSON.parse(sessionStorage.getItem("everyData"));
      let obj = {
        sj_name: everyDa.sj_name,
        lb_id: everyDa.xm,
        token: this.$store.state.$user.token,
        kmlb: everyDa.km,
        xlid: "",
        ctlx: "",
        sj_id: "",
        date: this.day.date,
        week: this.day.w
      };
      this.$api.paper.startDaily(obj).then(rst => {
        if (rst.data.event !== "100") return;
        this.colectId = rst.data.sj_id + "";
        const paper_config = this.paper_config,
          rst_data = rst.data;
        //保存试卷 , 试题基本信息
        paper_config.paper_info = rst_data;
        paper_config.single_Q_info = rst_data.d_info;
        paper_config.multiple_Q_info = rst_data.dx_info;
        paper_config.stuff_info = rst_data.cl_info;
        //Q  main
        const Q_data = rst_data.st_list;
        const single_Q_json = [],
          multiple_Q_json = [],
          stuff_Q_json = []; //区分单选 多选
        //保存懒加载状态
        lazy_load.total = rst_data.num;
        lazy_load.current_length = Q_data.length;
        Q_data.map(v => {
          switch (v.tx) {
            case "1":
              single_Q_json.push(v);
              break;
            case "2":
              multiple_Q_json.push(v);
              break;
            case "3":
              v.yx_da = "";
              v.nr = v.nr.replace(/\n+/g, "<br/>");
              stuff_Q_json.push(v);
              break;
          }
        });
        paper_config.single_Q_json = single_Q_json;
        paper_config.multiple_Q_json = multiple_Q_json;
        paper_config.stuff_Q_json = stuff_Q_json;
        console.log(paper_config, "paper_config---paper_config");
        //载剩余数据
        lazy_load.current_length < lazy_load.total && this.zjst_json();
        //倒计时
        this.count_down.total_time = this.count_down.remaining_time =
          rst_data.sc * 60 * 1000;
        this.start_count_down();
      });
    },

    // 章节练习
    zjst() {
      const lazy_load = this.lazy_load;
      const { product_id, paper_id } = this.$route.params;
      let obj = {
        lb_id: product_id,
        zj_id: paper_id,
        xlid: "",
        ctlx: "",
        token: this.$store.state.$user.token,
        page: lazy_load.page,
        size: lazy_load.size
      };

      this.$api.paper.zjSjindex22(obj).then(rst => {
        if (rst.data.event !== "100") return;

        this.colectId = rst.data.sj_id;
        const paper_config = this.paper_config,
          rst_data = rst.data;
        console.log(rst_data, "rst_data-----rst_data");
        rst_data.paper_id = paper_id; //todo 混合数据
        //保存试卷 , 试题基本信息
        paper_config.paper_info = rst_data;
        paper_config.single_Q_info = rst_data.d_info;
        paper_config.multiple_Q_info = rst_data.dx_info;
        paper_config.stuff_info = rst_data.cl_info;
        //Q  main
        const Q_data = rst_data.st_list;
        const single_Q_json = [],
          multiple_Q_json = [],
          stuff_Q_json = []; //区分单选 多选
        //保存懒加载状态
        lazy_load.total = rst_data.num;
        lazy_load.current_length = Q_data.length;
        Q_data.map(v => {
          switch (v.tx) {
            case "1":
              single_Q_json.push(v);
              break;
            case "2":
              multiple_Q_json.push(v);
              break;
            case "3":
              v.yx_da = "";
              v.nr = v.nr.replace(/\n+/g, "<br/>");
              stuff_Q_json.push(v);
              break;
          }
        });
        paper_config.single_Q_json = single_Q_json;
        paper_config.multiple_Q_json = multiple_Q_json;
        paper_config.stuff_Q_json = stuff_Q_json;
        console.log(paper_config, "paper_config---paper_config");
        //载剩余数据
        lazy_load.current_length < lazy_load.total && this.zjst_json();
        //倒计时
        this.count_down.total_time = this.count_down.remaining_time =
          rst_data.sc * 60 * 1000;
        this.start_count_down();
      });
    },

    zjst_json() {
      const paper_config = this.paper_config;
      const lazy_load = this.lazy_load;
      lazy_load.page++;
      this.$api.paper
        .zjSjindex22({
          lb_id: this.$route.params.product_id,
          sj_id: this.$route.params.paper_id,
          ctlx: "",
          xlid: "",
          token: this.$store.state.$user.token,
          page: lazy_load.page,
          size: lazy_load.size,
          DISABLED_LOADING: 1 //禁用loading
        })
        .then(rst => {
          if (rst.data.event !== "100") return;
          //copy
          const Q_data = rst.data.st_list;
          const single_Q_json = [],
            multiple_Q_json = [],
            stuff_Q_json = []; //区分单选 多选
          Q_data.map(v => {
            switch (v.tx) {
              case "1":
                single_Q_json.push(v);
                break;
              case "2":
                multiple_Q_json.push(v);
                break;
              case "3":
                v.yx_da = "";
                v.nr = v.nr.replace(/\n+/g, "<br/>");
                stuff_Q_json.push(v);
                break;
            }
          });
          paper_config.single_Q_json.push(...single_Q_json);
          paper_config.multiple_Q_json.push(...multiple_Q_json);
          paper_config.stuff_Q_json.push(...stuff_Q_json);
          //d递归
          lazy_load.current_length < lazy_load.total && this.zjst_json();
        });
    },

    init_Q_json() {
      let objC = JSON.parse(sessionStorage.getItem("wrObj"));
      let xlid = "";
      if (sessionStorage.getItem("wrObj")) {
        xlid = objC.xlId;
      } else {
        xlid = "";
      }
      const lazy_load = this.lazy_load;
      const { product_id, paper_id } = this.$route.params;

      this.$api.paper
        .detail_lazy({
          lb_id: product_id,
          sj_id: paper_id,
          ctlx: "",
          xlid: xlid,
          token: this.$store.state.$user.token,
          page: lazy_load.page,
          size: lazy_load.size
        })
        .then(rst => {
          if (rst.data.event !== "100") return;
          this.colectId = "";
          const paper_config = this.paper_config,
            rst_data = rst.data;
          rst_data.paper_id = paper_id; //todo 混合数据
          //保存试卷 , 试题基本信息
          if (!rst_data.cl_info.fz) {
            rst_data.cl_info.fz = 0;
          }
          this.bXlId = rst_data.xl_id + "";

          paper_config.paper_info = rst_data;
          paper_config.single_Q_info = rst_data.d_info;
          paper_config.multiple_Q_info = rst_data.dx_info;
          paper_config.stuff_info = rst_data.cl_info;
          //Q  main
          const Q_data = rst_data.st_list;
          const single_Q_json = [],
            multiple_Q_json = [],
            stuff_Q_json = []; //区分单选 多选
          //保存懒加载状态
          lazy_load.total = rst_data.num;
          lazy_load.current_length = Q_data.length;
          Q_data.map(v => {
            switch (v.tx) {
              case "1":
                single_Q_json.push(v);
                break;
              case "2":
                multiple_Q_json.push(v);
                break;
              case "3":
                v.yx_da = "";
                v.nr = v.nr.replace(/\n+/g, "<br/>");
                stuff_Q_json.push(v);
                break;
            }
          });
          // console.log(multiple_Q_json, "multiple_Q_json-----multiple_Q_json");
          paper_config.single_Q_json = single_Q_json;
          paper_config.multiple_Q_json = multiple_Q_json;
          paper_config.stuff_Q_json = stuff_Q_json;

          // paper_config.multiple_Q_json.forEach(item=>{
          //   console.log("1")
          //   item.yx_da=(item.yx_da)[0].split("")
          // })
          // console.log(paper_config.multiple_Q_json, "paper_config--------paper_config");

          //载剩余数据
          lazy_load.current_length < lazy_load.total && this.lazy_load_Q_json();
          //倒计时
          this.count_down.total_time = this.count_down.remaining_time =
            rst_data.sc * 60 * 1000;
          this.start_count_down();
        });
    },
    lazy_load_Q_json() {
      let objC = JSON.parse(sessionStorage.getItem("wrObj"));
      let xlid = "";
      if (sessionStorage.getItem("wrObj")) {
        xlid = objC.xlId;
      } else {
        xlid = "";
      }
      const paper_config = this.paper_config;
      const lazy_load = this.lazy_load;
      lazy_load.page++;
      this.$api.paper
        .detail_lazy({
          lb_id: this.$route.params.product_id,
          sj_id: this.$route.params.paper_id,
          ctlx: "",
          xlid: xlid,
          token: this.$store.state.$user.token,
          page: lazy_load.page,
          size: lazy_load.size,
          DISABLED_LOADING: 1 //禁用loading
        })
        .then(rst => {
          if (rst.data.event !== "100") return;

          //copy
          const Q_data = rst.data.st_list;
          const single_Q_json = [],
            multiple_Q_json = [],
            stuff_Q_json = []; //区分单选 多选
          Q_data.map(v => {
            switch (v.tx) {
              case "1":
                single_Q_json.push(v);
                break;
              case "2":
                multiple_Q_json.push(v);
                break;
              case "3":
                v.yx_da = "";
                v.nr = v.nr.replace(/\n+/g, "<br/>");
                stuff_Q_json.push(v);
                break;
            }
          });
          paper_config.single_Q_json.push(...single_Q_json);
          paper_config.multiple_Q_json.push(...multiple_Q_json);
          paper_config.stuff_Q_json.push(...stuff_Q_json);

          // this.$nextTick(() => {
          //   paper_config.multiple_Q_json.forEach(item => {
          //     if (item.yx_da.length != 0) {
          //       item.yx_da = item.yx_da[0].split("");
          //     }
          //   });
          // });
          if (
            paper_config.multiple_Q_info.zs * 1 ==
            paper_config.multiple_Q_json.length
          ) {
            paper_config.multiple_Q_json.forEach(element => {
              if (element.yx_da.length == 0) return;
              element.yx_da = element.yx_da[0].split("");
            });
          }

          //d递归
          lazy_load.current_length < lazy_load.total && this.lazy_load_Q_json();
        });
    },
    scroll2dom(dom_query) {
      window.$plus.scroll2dom(document.querySelector(dom_query));
    },
    start_count_down() {
      //#start 这里处理一下试题 , 暂停之后不能选 ,开始之后可以选
      this.paper_config.single_Q_json.map(v => (v.disabled = false));
      this.paper_config.multiple_Q_json.map(v => (v.disabled = false));
      //#end
      this.count_down.use = true;
      this.count_down.is_pause = false;
      this.count_down.remaining_time -= 1000;
      this.count_down.timer = setInterval(() => {
        this.count_down.remaining_time -= 1000;
      }, 1000);
    },
    pause_count_down() {
      //#start 这里处理一下试题 , 暂停之后不能选 ,开始之后可以选
      this.paper_config.single_Q_json.map(v => (v.disabled = true));
      this.paper_config.multiple_Q_json.map(v => (v.disabled = true));
      //#end
      this.count_down.use = false;
      this.count_down.is_pause = true;
      clearInterval(this.count_down.timer);
    },
    //modal
    use_submit_tip_modal(not_compile_Q_num) {
      this.submit_tip_modal.use = true;
      this.submit_tip_modal.not_compile_Q_num = not_compile_Q_num;
    },

    // 智能练习 重新测试
    redoAiJl() {
      const lazy_load = this.lazy_load;
      let obj = JSON.parse(sessionStorage.getItem("conData"));
      this.$api.paper.redoAiJl(obj).then(rst => {
        if (rst.data.event !== "100") return;
        this.colectId = rst.data.sj_id + "";
        const paper_config = this.paper_config,
          rst_data = rst.data;

        //保存试卷 , 试题基本信息
        paper_config.paper_info = rst_data;
        paper_config.single_Q_info = rst_data.d_info;
        paper_config.multiple_Q_info = rst_data.dx_info;
        paper_config.stuff_info = rst_data.cl_info;
        //Q  main
        const Q_data = rst_data.st_list;
        const single_Q_json = [],
          multiple_Q_json = [],
          stuff_Q_json = []; //区分单选 多选
        //保存懒加载状态
        lazy_load.total = rst_data.num;
        lazy_load.current_length = Q_data.length;
        Q_data.map(v => {
          switch (v.tx) {
            case "1":
              single_Q_json.push(v);
              break;
            case "2":
              multiple_Q_json.push(v);
              break;
            case "3":
              v.yx_da = "";
              v.nr = v.nr.replace(/\n+/g, "<br/>");
              stuff_Q_json.push(v);
              break;
          }
        });
        paper_config.single_Q_json = single_Q_json;
        paper_config.multiple_Q_json = multiple_Q_json;
        paper_config.stuff_Q_json = stuff_Q_json;
        console.log(paper_config, "paper_config----paper_config");
        //倒计时
        this.count_down.total_time = this.count_down.remaining_time =
          rst_data.sc * 60 * 1000;
        this.start_count_down();
      });
    },
    setData() {
      that.lookDat = "查看";
    },
    // 万人模考报名
    dryrunBm(data) {
      let obj = {
        lb_id: data.lb_id,
        kmlb: data.kmlb,
        token: this.$store.state.$user.token,
        sj_id: data.id
      };
      this.$api.paper.dryrunBm(obj).then(res => {
        if (res.data.event != "100")
          return this.$Message.error("报名是被，请刷新页面后再试");
        this.modal1 = true;
        this.wrList();
      });
    },
    // 万人模考排行
    dryrunList() {
      let wr_obj = JSON.parse(sessionStorage.getItem("wrObj"));
      let obj = {
        lb_id: wr_obj.lb_id,
        token: this.$store.state.$user.token,
        kmlb: wr_obj.kmlb,
        sj_id: wr_obj.id
      };
      this.$api.paper.dryrunList(obj).then(res => {
        if (res.data.event == "100") {
          this.paper_exam_result = res.data;
        }
      });
    },
    // 查看结果
    lookEnd(data) {
      this.dryrunList();
      // let isJ = moment(data).isAfter(this.gbTime.jTime);
      // let isF = moment(data).isAfter(this.gbTime.fTime);
      // let isG = moment(data).isAfter(this.gbTime.gTime);
      // let isS = moment(data).isAfter(this.gbTime.sTime);
      // let isZ = moment(data).isAfter(this.gbTime.zTime)
      // if (isJ && this.wr_obj.major == "经济") {
      //   this.dryrunList();
      // } else if (isF && this.wr_obj.major == "法规") {
      //   this.dryrunList();
      // } else if (isG && this.wr_obj.major == "管理") {
      //   this.dryrunList();
      // } else if (isS && this.wr_obj.major == "市政") {
      //   this.dryrunList();
      // } else if (isZ && this.wr_obj.major == "建筑") {
      //   this.dryrunList();
      // }
    },
    fwTime() {
      let obj = {
        token: this.$store.state.$user.token || ""
      };
      this.$api.paper.getTimeStamp(obj).then(res => {
        let dayD = new Date(res.data.service_time * 1000);
        let y = dayD.getFullYear();
        let m = (dayD.getMonth() + 1 + "").padStart(2, "0");
        let d = (dayD.getDate() + "").padStart(2, "0");
        let h = (dayD.getHours() + "").padStart(2, "0");
        let mm = (dayD.getMinutes() + "").padStart(2, "0");
        let s = (dayD.getSeconds() + "").padStart(2, "0");
        let str = `${y}-${m}-${d} ${h}:${mm}:${s}`;
        this.lookEnd(str);
      });
    }
  },
  computed: {
    day() {
      let week = [
        "星期日",
        "星期一",
        "星期二",
        "星期三",
        "星期四",
        "星期五",
        "星期六"
      ];
      let dObj = {};
      let d = new Date();
      let y = d.getFullYear();
      let m = (d.getMonth() + 1 + "").padStart(2, 0);
      let r = (d.getDate() + "").padStart(2, 0);
      let w = d.getDay();
      let date = `${y}-${m}-${r}`;
      dObj.date = date;
      dObj.w = week[w];
      return dObj;
    },
    text_remaining_time() {
      const text_time_info = this.count_down.remaining_time.toTime();
      return text_time_info;
      // return text_time_info.h + ':' + text_time_info.m + ':' + text_time_info.s;
    },
    text_pass_time() {
      const text_time_info = (this.count_down.pass_time =
        this.count_down.total_time - this.count_down.remaining_time).toTime();
      return text_time_info.h + ":" + text_time_info.m + ":" + text_time_info.s;
    }
  },
  beforeCreate() {
    //immersion_nav
    /*
    this.$store.state.use_immersion_nav = false;
    this.$is_auth(true);
    */
  },
  mounted() {
    this.settimer();
  },
  created() {
    // this.cjShow()

    this.wr_obj = JSON.parse(sessionStorage.getItem("wrObj"));
    window.addEventListener("scroll", this.pxscroll);
    this.request_id = this.$route.params.st_lx + "";
    if (this.$route.params.st_lx == "2") {
      //章节
      this.zjst();
    } else if (
      this.$route.params.st_lx == "1" ||
      this.$route.params.st_lx == "5"
    ) {
      //普通
      if (sessionStorage.getItem("phlists") == "look") {
        // this.lookEnd()
        this.fwTime();
      } else if (sessionStorage.getItem("resObj")) {
        this.paper_exam_result = JSON.parse(sessionStorage.getItem("resObj"));
      } else {
        this.$nextTick(() => {
          this.init_Q_json();
        });
      }
    } else if (this.$route.params.st_lx == "3") {
      //智能练习
      if (!sessionStorage.getItem("conData")) {
        this.aiJl();
      } else {
        this.redoAiJl();
      }
    } else if (this.$route.params.st_lx == "4") {
      //每日一练
      if (!sessionStorage.getItem("daylay")) {
        this.startDaily();
      } else {
        this.redoDaily();
      }
    }
  },
  beforeRouteLeave(to, from, next) {
    if (to.name != "wanExam" && to.name != "AllPaper") {
      sessionStorage.removeItem("wrObj");
      sessionStorage.removeItem("wrlists");
    } else if (!this.paper_exam_result && this.$route.params.st_lx == "5") {
      this.tcbc();
    }
    next();
  },

  beforeDestroy() {
    sessionStorage.removeItem("conData");
    sessionStorage.removeItem("daylay");
    sessionStorage.removeItem("resObj");
    sessionStorage.removeItem("phlists");
    clearInterval(this.count_down.timer);
    clearInterval(this.timers);
    window.removeEventListener("scroll", this.pxscroll);
  }
};
